package com.msr.common;

import java.sql.Connection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;

public class DbSource {

	public DataSource getDs() throws Exception {
		Context initCtx = null;
		initCtx = new InitialContext();
		DataSource ds = (DataSource) initCtx.lookup(SysConstant.SYS_JNDINAME);
		return ds;
	}

	public Dao getDao() throws Exception {
		Context initCtx = null;
		initCtx = new InitialContext();
		DataSource ds = (DataSource) initCtx.lookup(SysConstant.SYS_JNDINAME);
		return new NutDao(ds);
	}

	public Connection getConn() throws Exception {

		Context initCtx = null;
		Connection conn = null;
		initCtx = new InitialContext();
		DataSource ds = (DataSource) initCtx.lookup(SysConstant.SYS_JNDINAME);
		conn = ds.getConnection();
		return conn;
	}
}
